package com.fanco.learn_datastruct_leetcode.designpattern.iterator;

import java.util.Iterator;
import java.util.List;

/**
 * @author qiaowang 2022/2/22
 * 描述
 */
public class InfoColleageIterator implements Iterator {

    List<Department> departmentList; // 信息工程学院是以list方式存放数据的。
    int index = -1;


    public InfoColleageIterator(List<Department> departmentList) {
        this.departmentList = departmentList;
    }

    /**
     * Returns {@code true} if the iteration has more elements.
     * (In other words, returns {@code true} if {@link #next} would
     * return an element rather than throwing an exception.)
     *
     * @return {@code true} if the iteration has more elements
     */
    @Override
    public boolean hasNext() {
        if (index >= departmentList.size() - 1) {
            return false;
        } else {
            index += 1;
            return true;
        }
    }

    /**
     * Returns the next element in the iteration.
     *
     * @return the next element in the iteration
     * @throws NoSuchElementException if the iteration has no more elements
     */
    @Override
    public Object next() {
        return departmentList.get(index);
    }

    @Override
    public void remove() {

    }
}

